package cat

import (
	"os"

	conf "gitee.com/familydoc/plugin/config"
	"github.com/sirupsen/logrus"
)

var logger = logrus.New()

func logSetup() {
	logger.Out = os.Stdout

	//设置输出样式，自带的只有两种样式logrus.JSONFormatter{}和logrus.TextFormatter{}
	if conf.LogFormatter == "json" {
		logger.SetFormatter(&logrus.JSONFormatter{})
	} else {
		logger.SetFormatter(&logrus.TextFormatter{})
	}

	logger.WithFields(logrus.Fields{
		"app_id":      conf.AppId,
		"server_host": conf.AppAddr,
		"host_name":   conf.Hostname,
	})
	//设置日志输出级别
	if level, err := logrus.ParseLevel(conf.LogLevel); err == nil {
		logger.SetLevel(level)
	} else if conf.RunMode == "debug" {
		logger.SetLevel(logrus.DebugLevel)
	} else {
		logger.SetLevel(logrus.ErrorLevel)
	}
}
